import { defineStore } from 'pinia'
// import { privateRoutes } from '@/router'
import router from '@/router'
import { ref } from 'vue'
export const usePermissionStore = defineStore('permissionStore', () => {
  const routes = ref([])
  const hasRoute = ref(false)
  const firstRoutePath = ref('')
  // const setRoutes =  (menus) => {
  //   menus.forEach((menu) =>
  //     routes.value.push(privateRoutes.find((privateRoute) => privateRoute.name === menu))
  //   )
  //   console.log(routes.value);
  //   routes.value.forEach((route) => router.addRoute(route))
  //   hasRoute.value = true
  // }
  const setRoutes = (data) => {
    routes.value = data
    // 动态添加路由的第一个路由的path
    firstRoutePath.value = data[0].children[0].path
    console.log(firstRoutePath.value)
    // 动态添加路由
    routes.value.forEach((route) => router.addRoute(route))
    hasRoute.value = true
  }
  // 移除所有路由
  const removeRoutes = () => {
    routes.value.forEach((route) => {
      router.removeRoute(route.name)
      console.log(route)
    })
    hasRoute.value = false
  }
  return { routes, hasRoute, firstRoutePath, setRoutes, removeRoutes }
})
